<?php

/*
 * Example 1 from
 * http://www.php.net/manual/en/language.types.integer.php
 */


/*
 * Create an instance of IndentedTextWriter to hold the generated code
 */

$writer = new IndentedTextWriter();

/*
 * Create an instance of the code generator options class
 */

$options = new CodeGeneratorOptions();

/*
 * Set the bracing style:
 */

$options->set_BracingStyle(BracingStyle::KR);

/*
 * both $writer and $options will be arguments to one of
 * the PHPCodeProvider code generating methods.
 * Create an instance of the PHP code provider class
 */

$provider = new PHPCodeProvider();

/*
 * Start creating the code tree.
 */

$defaultNamespace = new CodeNamespace();

/*
 * $a appears several times in the example
 * so create a reference to it
 */

$a_ref = new VariableReferenceExpression('a');

/*
 * Start adding statements to the namespace.
 */

$assign_statement_1 = new AssignStatement($a_ref, new PrimitiveExpression(1234));
$assign_statement_2 = new AssignStatement($a_ref, new PrimitiveExpression(-123));
$assign_statement_3 = new AssignStatement($a_ref, new PrimitiveExpression(0123));
$assign_statement_4 = new AssignStatement($a_ref, new PrimitiveExpression(0x1A));

/*
 * Add the statements to the default namespace
 */

$defaultNamespace->Statements->add($assign_statement_1);
$defaultNamespace->Statements->add($assign_statement_2);
$defaultNamespace->Statements->add($assign_statement_3);
$defaultNamespace->Statements->add($assign_statement_4);

/*
 * Generate the code
 */

$provider->generateCodeFromNamespace($defaultNamespace, $writer, $options);

/*
 * Print the generated code
 */

echo 
    '<pre>' . str_replace(
        '<br />', '', highlight_string($writer->get_String(), true)) . 
    '<pre/>';

/*
 * The output should be:
 * (no support for octal or hexadecimal integers)
 * 
 * $a = 1234;
 * $a = -123;
 * $a = 83;
 * $a = 26;
 * 
 */


?>
